package com.ganbo.stock.controller;


import com.ganbo.stock.service.impl.FundServiceImpl;
import com.ganbo.stock.service.impl.FundStockLastHistoryServiceImpl;
import com.ganbo.stock.service.impl.FundStockLastServiceImpl;
import com.ganbo.stock.service.impl.FundStockServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class FundController {

    @Autowired
    FundServiceImpl fundServiceImpl;
    @Autowired
    FundStockServiceImpl fundStockServiceImpl;
    @Autowired
    FundStockLastServiceImpl fundStockLastServiceImpl;
    @Autowired
    FundStockLastHistoryServiceImpl fundStockLastHistoryServiceImpl;


    @GetMapping("/initStock")
    public void groupMessageFailRetryTask() {
        log.info("==================更新开始======");
        fundServiceImpl.init(); //拉取优质基金信息
        fundStockServiceImpl.fetchFundStockTask();      //拉取优质基金的持仓股票信息
        fundStockLastServiceImpl.initFundStockLast();   //生成基金持仓最多的股票
        fundStockLastServiceImpl.updateFundStockLastTodayReal(); //更新股票当日盘口信息
        fundStockLastServiceImpl.generateTodayHistory();         //将当天生成数据备份到历史表
        fundStockLastHistoryServiceImpl.analyseTodayStockPool(); //分析推荐股票
        log.info("==================更新完毕======");
    }

    /**
     * 获取最近表现好的基金，并抓取这些基金所持仓的股票
     */
    @GetMapping("/fund/init")
    public String init() {
        fundServiceImpl.init();
        return "SUCCESS";
    }


    @GetMapping("/fundStock/init")
    public String fundStockInit() {
        fundStockServiceImpl.fetchFundStockTask();
        return "SUCCESS";
    }

    @GetMapping("/updateFundStockLastTodayReal")
    public String initFundStockLast() {
        fundStockLastServiceImpl.updateFundStockLastTodayReal();
        return "SUCCESS";
    }

    @GetMapping("/generateTodayHistory")
    public String generateTodayHistory() {
        fundStockLastServiceImpl.generateTodayHistory();         //将当天生成数据备份到历史表
        fundStockLastHistoryServiceImpl.analyseTodayStockPool(); //分析推荐股票
        return "success";
    }

}
